import axios from "axios";
import { ElMessage } from 'element-plus'
import router from "../router/index"
const methods = ['get', 'post', 'delete']
const baseUrl = ''
const contentTypes = ['application/json', 'multipart/form-data']
//0表示json，1表示formdata
export default function request(url, data, methodIndex, contentTypeIndex) {
  return new Promise((resolve, reject) => {
    axios({
      baseURL: baseUrl,
      url,
      method: methods[methodIndex],
      params: methodIndex == 0 ? data : {},
      data,
      headers: {
        'Authorization': localStorage.getItem('Authorization') || null,
        'Content-Type': contentTypes[contentTypeIndex || 0],
      },
      // responseType: 'blob',
    }).then(res => {
      resolve(res.data)
    }).catch((e) => {
      ElMessage({
        message: e.message,
        type: 'error'
      })
    })
  })
}